/** \file Heap_t.cc 
 * Test definitions for the class Heap.
 *
 * (C) Copyright 2003-2006 by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: Heap_t.cc 117 2006-06-19 06:49:41Z semihc $
 *
 *
 */


#include "HeapMgr.hh"
#include "HeapDbg.hh"
#include <cstdlib>
#include "TestHarness.hh"
#include "Debug.hh"

using namespace std;
using namespace TC;
using namespace TC::test;

TC_DEF_FILE("$Revision: 117 $");

namespace {

  struct A
  {
    long m[111];
  };
  

}


namespace TC {

  namespace test {

    bool Heap_test()
    {
      TC_LOG_FUNC(Heap_test);

      HeapDbg hd;

      void* mptr = hd.newMem(100, Heap::e_Scalar);
      TC_ASSERT(mptr);
      memset(mptr,0,100);
      hd.deleteMem(mptr, Heap::e_Scalar);

      Heap* oldHeap = HeapMgr::SetCurrentHeap(&hd);
      HeapMgr::GetCurrentHeap()->resetStats();

      
      A* aptr1 = new A;
      A* aptr2 = new A[2];
      A* aptr3 = new (nothrow) A;
      A* aptr4 = new (nothrow) A[5];
      A* aptr5 = new (hd) A;
      A* aptr6 = new (hd) A[7];

      delete aptr1;
      delete[] aptr2;
      delete aptr3;
      delete[] aptr4;
      operator delete(aptr5,hd);
      operator delete[](aptr6,hd);

      HeapMgr::GetCurrentHeap()->printStats();
      HeapMgr::SetCurrentHeap(oldHeap);

      return true;
    }

  }
} // end namespace
